package com.campus.controller;

import com.campus.pojo.dto.SportsVenuePageQueryDTO;
import com.campus.pojo.entity.SportsVenue;
import com.campus.pojo.vo.SportsVenueVO;
import com.campus.result.PageResult;
import com.campus.result.Result;
import com.campus.pojo.dto.SportsVenueDTO;
import com.campus.service.SportsVenueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sportsVenue")
@Slf4j
public class SportsVenueController {
    
    @Autowired
    private SportsVenueService sportsVenueService;

    /**
     * 新增体育场馆
     *
     * @param sportsVenueDTO
     * @return
     */
    @PostMapping
    public Result save(@RequestBody SportsVenueDTO sportsVenueDTO) {
        log.info("新增体育场馆：{}", sportsVenueDTO);
        sportsVenueService.save(sportsVenueDTO);
        return Result.success();
    }

    /**
     * 批量删除 前端传递ids数组 根据id批量删除 可以利用数组或者集合接收 推荐集合
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result deleteByIds(@RequestParam List<Long> ids) {
        log.info("批量删除体育场馆 ids：{}", ids);
        sportsVenueService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 分页查询体育场馆 get请求 spring会将接收到的查询参数自动封装成dto对象
     * @return
     */
    @GetMapping("/pageQuery")
    public Result<PageResult<SportsVenueVO>> pageQuery(SportsVenuePageQueryDTO sportsVenuePageQueryDTO) {
        log.info("体育场馆分页查询：{}", sportsVenuePageQueryDTO);
        PageResult<SportsVenueVO> pageResult = sportsVenueService.pageQuery(sportsVenuePageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 预约体育场馆-修改状态
     */
    @PutMapping("/book/{id}/{status}")
    public Result book(@PathVariable Long id, @PathVariable Integer status) {
        log.info("预约体育场馆id: {}  修改状态为：{}", id, status);
        sportsVenueService.updateStatus(id, status);
        return Result.success();
    }

    /**
     * 查询回显
     */
    @GetMapping("/{id}")
    public Result<SportsVenue> getById(@PathVariable Long id) {
        log.info("查询回显 id: {}", id);
        SportsVenue sportsVenue = sportsVenueService.getById(id);
        return Result.success(sportsVenue);
    }

    /**
     * 修改体育场馆信息
     */
    @PutMapping
    public Result update(@RequestBody SportsVenueDTO sportsVenueDTO) {
        log.info("修改体育场馆信息：{}", sportsVenueDTO);
        sportsVenueService.update(sportsVenueDTO);
        return Result.success();
    }
}
